<?php 
// Validation Fucntions
function _register_parent_demographic_info_validate($form, &$form_state) {
    $values = $form_state['values'];
    if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $form_state['values']['email'])) {
        form_set_error('invalid_email', t('Please enter a valid email.'));
    }
     else if(user_load_by_mail($values["email"])){
        form_set_error('email', t("Email address already registered with another user."));
    }
    if(user_load_by_name($form_state['values']['username'])){
        form_set_error('username', t("Username already exists."));
    }
    if (strlen($form_state['values']['password']) < 5) {
        form_set_error('password_length', t('Passwords must be more than 4 characters'));
    }
    if ($form_state['values']['password'] != $form_state['values']['confirm_password']) {//confirm_password
        form_set_error('password_match', t('Passwords don\'t match'));
    }
}
function _register_yp_demographic_info_validate($form, &$form_state){
    if (strlen($form_state['values']['yp_email'])>4&&!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $form_state['values']['yp_email'])) {
        form_set_error('invalid_email', t('Please enter a valid email.'));
    }
//    if (strlen($form_state['values']['yp_password']) < 5) {
//        form_set_error('password_length', t('Passwords must be more than 4 characters'));
//    }
//    if ($form_state['values']['yp_password'] != $form_state['values']['yp_confirm_password']) {//confirm_password
//        form_set_error('password_match', t('Passwords don\'t match'));
//    }
}
function _register_parent_address_validate($form, &$form_state) {
    
    $values = $form_state['values'];
    $form_key = "parent_addresses";
    
    foreach ($values[$form_key] as $address_data) {
        
//        if ($address_data['zip']<9000 || strlen($address_data['zip'])!=5) {
//            form_set_error('invalid_zip', t('Please enter a valid zip'));
//        }
      
    }
}
function register_parent_eligibility_validate($form, &$form_state) {
    
}